package com.rp.quartz;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.Trigger;
import org.springframework.jdbc.core.JdbcTemplate;

import com.rp.common.utils.RpUtil;
import com.rp.system.po.Task;

/**
 * 
 * @author Administrator
 *
 */
public class JobExpand {
	
	public void updateTask(JobExecutionContext context){
		Trigger trigger = context.getTrigger();
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String endTime = sdf.format(trigger.getEndTime());
		String today = sdf.format(new Date());
		
		if(endTime.equals(today)){
			JdbcTemplate jdbcTemplate = (JdbcTemplate) RpUtil.getBean("jdbcTemplate");
			
			JobDetail jobDetail = context.getJobDetail();
			String taskName = jobDetail.getName();
			
			jdbcTemplate.execute("UPDATE RP_SYSTEM_TASKS SET taskStatus = '"+Task.COMPLETE+"' WHERE taskName = '"+taskName+"'");
			
		}
	}

}
